{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 字符串数据的处理\n",
    "\n",
    "* 下周考试，内容之前学过所有内容，后面所学会有所侧重，时间1节课，形式和上次一样(数据文件读入详解不考)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pylab\n",
    "import math\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import json\n",
    "import matplotlib.pyplot as plt\n",
    "from pandas.io.json import json_normalize"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 不规范的json数据导入\n",
    "\n",
    "* 淘宝某男鞋品牌商品详情数据（网络爬取）\n",
    "https://pan.baidu.com/s/1Fmt1yacISXCjxkPTd-TiVA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "op1=open(r'D:\\try\\shoes.json', 'r',encoding='utf-8')\n",
    "li=[]\n",
    "dict1={}\n",
    "for i in op1:\n",
    "    k=json.loads(i.encode(\"utf-8\"))#把字符串转换为json\n",
    "    li.append(k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'_id': {'$oid': '5aa77041be9b0338dc1faab4'},\n",
       " 'title': '意尔康男鞋2018春季新款英伦真皮商务休闲皮鞋青年男士皮鞋子男潮',\n",
       " 'url': 'http://detail.tmall.com/item.htm?id=562121114807&ns=1&abbucket=9',\n",
       " 'price': '269.00',\n",
       " 'location': '浙江 丽水',\n",
       " 'sales': '1583人付款',\n",
       " 'nick': '意尔康皮鞋旗舰店',\n",
       " 'itemid': '562121114807',\n",
       " 'info': {'上市年份季节': '2018年春季',\n",
       "  '货号': '8142ZR90254W',\n",
       "  '销售渠道类型': '商场同款(线上线下都销售)',\n",
       "  '鞋垫材质': 'PU',\n",
       "  '品牌': 'YEARCON/意尔康',\n",
       "  '鞋头款式': '圆头',\n",
       "  '闭合方式': '松紧带',\n",
       "  '鞋底材质': '塑胶',\n",
       "  '鞋面材质': '头层牛皮（除牛反绒）',\n",
       "  '真皮材质工艺': '纳帕纹',\n",
       "  '鞋面内里材质': 'PU',\n",
       "  '鞋制作工艺': '注压鞋',\n",
       "  '跟底款式': '平跟',\n",
       "  '图案': '纯色',\n",
       "  '风格': '商务',\n",
       "  '细分风格': '商务休闲',\n",
       "  '场合': '日常',\n",
       "  '季节': '春秋',\n",
       "  '颜色分类': '黑色土黄',\n",
       "  '尺码': '383940414243',\n",
       "  '款式': '商务休闲鞋',\n",
       "  '功能': '轻质',\n",
       "  '适用对象': '青年（18-40周岁）',\n",
       "  '低帮鞋品名': '商务休闲鞋'}}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "li[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "a=json_normalize(li)#把json数据转化为数据框"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据说明\n",
    "\n",
    "* 淘宝搜索下通常有5000个商品\n",
    "* 销量意义\n",
    "* 大量商品的详情信息特征是空缺的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4987"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['_id.$oid', 'info.上市年份季节', 'info.上市时间', 'info.产品名称', 'info.低帮鞋品名',\n",
       "       'info.功能', 'info.吊牌价', 'info.品牌', 'info.图案', 'info.场合', 'info.外底材料',\n",
       "       'info.季节', 'info.尺码', 'info.帮面内里材质', 'info.帮面材质', 'info.性别',\n",
       "       'info.是否商场同款', 'info.是否瑕疵', 'info.款号', 'info.款式', 'info.流行元素',\n",
       "       'info.真皮材质工艺', 'info.细分风格', 'info.货号', 'info.跟底款式', 'info.运动系列',\n",
       "       'info.运动鞋科技', 'info.适合路面', 'info.适用对象', 'info.销售渠道类型', 'info.闭合方式',\n",
       "       'info.靴子品名', 'info.靴筒内里材质', 'info.靴筒材质', 'info.靴筒高度', 'info.鞋制作工艺',\n",
       "       'info.鞋垫材质', 'info.鞋头款式', 'info.鞋底材质', 'info.鞋码', 'info.鞋跟高',\n",
       "       'info.鞋面内里材质', 'info.鞋面材质', 'info.颜色分类', 'info.风格', 'itemid',\n",
       "       'location', 'nick', 'price', 'sales', 'title', 'url'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "#a[\"info.上市年份季节\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0                       黑色土黄\n",
       "1     黑色棕色黑色加绒版棕色加绒版黑色镂空棕色镂空\n",
       "2                         黑色\n",
       "3    黑色真皮 棕色真皮 黑色加绒真皮 棕色加绒真皮\n",
       "4                   黑色单鞋土黄单鞋\n",
       "Name: info.颜色分类, dtype: object"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[\"info.颜色分类\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>_id.$oid</th>\n",
       "      <th>info.上市年份季节</th>\n",
       "      <th>info.上市时间</th>\n",
       "      <th>info.产品名称</th>\n",
       "      <th>info.低帮鞋品名</th>\n",
       "      <th>info.功能</th>\n",
       "      <th>info.吊牌价</th>\n",
       "      <th>info.品牌</th>\n",
       "      <th>info.图案</th>\n",
       "      <th>info.场合</th>\n",
       "      <th>...</th>\n",
       "      <th>info.鞋面材质</th>\n",
       "      <th>info.颜色分类</th>\n",
       "      <th>info.风格</th>\n",
       "      <th>itemid</th>\n",
       "      <th>location</th>\n",
       "      <th>nick</th>\n",
       "      <th>price</th>\n",
       "      <th>sales</th>\n",
       "      <th>title</th>\n",
       "      <th>url</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5aa77041be9b0338dc1faab4</td>\n",
       "      <td>2018年春季</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>商务休闲鞋</td>\n",
       "      <td>轻质</td>\n",
       "      <td>NaN</td>\n",
       "      <td>YEARCON/意尔康</td>\n",
       "      <td>纯色</td>\n",
       "      <td>日常</td>\n",
       "      <td>...</td>\n",
       "      <td>头层牛皮（除牛反绒）</td>\n",
       "      <td>黑色土黄</td>\n",
       "      <td>商务</td>\n",
       "      <td>562121114807</td>\n",
       "      <td>浙江 丽水</td>\n",
       "      <td>意尔康皮鞋旗舰店</td>\n",
       "      <td>269.00</td>\n",
       "      <td>1583人付款</td>\n",
       "      <td>意尔康男鞋2018春季新款英伦真皮商务休闲皮鞋青年男士皮鞋子男潮</td>\n",
       "      <td>http://detail.tmall.com/item.htm?id=5621211148...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5aa77042be9b0338dc1faab5</td>\n",
       "      <td>2017年秋季</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>商务休闲鞋</td>\n",
       "      <td>轻质</td>\n",
       "      <td>NaN</td>\n",
       "      <td>YEARCON/意尔康</td>\n",
       "      <td>纯色</td>\n",
       "      <td>办公室</td>\n",
       "      <td>...</td>\n",
       "      <td>头层牛皮（除牛反绒）</td>\n",
       "      <td>黑色棕色黑色加绒版棕色加绒版黑色镂空棕色镂空</td>\n",
       "      <td>商务</td>\n",
       "      <td>545941839337</td>\n",
       "      <td>浙江 丽水</td>\n",
       "      <td>意尔康皮鞋旗舰店</td>\n",
       "      <td>199.00</td>\n",
       "      <td>1607人付款</td>\n",
       "      <td>意尔康旗舰店官方店男鞋春秋真皮爸爸鞋中老年人商务休闲皮鞋子男</td>\n",
       "      <td>http://detail.tmall.com/item.htm?id=5459418393...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2 rows × 52 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                   _id.$oid info.上市年份季节 info.上市时间 info.产品名称 info.低帮鞋品名  \\\n",
       "0  5aa77041be9b0338dc1faab4     2018年春季       NaN       NaN      商务休闲鞋   \n",
       "1  5aa77042be9b0338dc1faab5     2017年秋季       NaN       NaN      商务休闲鞋   \n",
       "\n",
       "  info.功能 info.吊牌价      info.品牌 info.图案 info.场合  \\\n",
       "0      轻质      NaN  YEARCON/意尔康      纯色      日常   \n",
       "1      轻质      NaN  YEARCON/意尔康      纯色     办公室   \n",
       "\n",
       "                         ...                           info.鞋面材质  \\\n",
       "0                        ...                          头层牛皮（除牛反绒）   \n",
       "1                        ...                          头层牛皮（除牛反绒）   \n",
       "\n",
       "                info.颜色分类 info.风格        itemid location      nick   price  \\\n",
       "0                    黑色土黄      商务  562121114807    浙江 丽水  意尔康皮鞋旗舰店  269.00   \n",
       "1  黑色棕色黑色加绒版棕色加绒版黑色镂空棕色镂空      商务  545941839337    浙江 丽水  意尔康皮鞋旗舰店  199.00   \n",
       "\n",
       "     sales                             title  \\\n",
       "0  1583人付款  意尔康男鞋2018春季新款英伦真皮商务休闲皮鞋青年男士皮鞋子男潮   \n",
       "1  1607人付款    意尔康旗舰店官方店男鞋春秋真皮爸爸鞋中老年人商务休闲皮鞋子男   \n",
       "\n",
       "                                                 url  \n",
       "0  http://detail.tmall.com/item.htm?id=5621211148...  \n",
       "1  http://detail.tmall.com/item.htm?id=5459418393...  \n",
       "\n",
       "[2 rows x 52 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "_id.$oid          0\n",
       "info.上市年份季节    4483\n",
       "info.上市时间      4986\n",
       "info.产品名称      4978\n",
       "info.低帮鞋品名     4512\n",
       "info.功能         403\n",
       "info.吊牌价       4986\n",
       "info.品牌           5\n",
       "info.图案         209\n",
       "info.场合         312\n",
       "info.外底材料      4986\n",
       "info.季节         273\n",
       "info.尺码           1\n",
       "info.帮面内里材质    4944\n",
       "info.帮面材质      4944\n",
       "info.性别        4986\n",
       "info.是否商场同款    4986\n",
       "info.是否瑕疵      4986\n",
       "info.款号        4986\n",
       "info.款式          14\n",
       "info.流行元素       480\n",
       "info.真皮材质工艺    1840\n",
       "info.细分风格       809\n",
       "info.货号         751\n",
       "info.跟底款式       243\n",
       "info.运动系列      4986\n",
       "info.运动鞋科技     4986\n",
       "info.适合路面      4986\n",
       "info.适用对象       781\n",
       "info.销售渠道类型    4549\n",
       "info.闭合方式         6\n",
       "info.靴子品名      4984\n",
       "info.靴筒内里材质    4983\n",
       "info.靴筒材质      4983\n",
       "info.靴筒高度      4983\n",
       "info.鞋制作工艺      192\n",
       "info.鞋垫材质      1356\n",
       "info.鞋头款式        12\n",
       "info.鞋底材质       218\n",
       "info.鞋码        4986\n",
       "info.鞋跟高        799\n",
       "info.鞋面内里材质      44\n",
       "info.鞋面材质         7\n",
       "info.颜色分类         0\n",
       "info.风格         183\n",
       "itemid            0\n",
       "location          0\n",
       "nick              0\n",
       "price             0\n",
       "sales             0\n",
       "title             0\n",
       "url               0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.isnull().sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课间题\n",
    "\n",
    "* 请利用老师的代码导入数据，并输出数据的前五行\n",
    "\n",
    "* 输出所有的列标"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 求出价格均值\n",
    "\n",
    "注意此数据框价格默认是字符串，需要改变对应列类型才能求均值，具体改变方法见链接\n",
    "https://www.cnblogs.com/xitingxie/p/8426340.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "293.0891818728715"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.price.astype(float).mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 求价格的分位数（describe）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    4987.000000\n",
       "mean      293.089182\n",
       "std       293.797594\n",
       "min        16.900000\n",
       "25%       178.000000\n",
       "50%       258.000000\n",
       "75%       356.000000\n",
       "max      6999.000000\n",
       "Name: price, dtype: float64"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.to_numeric(a.price).describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    4987.000000\n",
       "mean      293.089182\n",
       "std       293.797594\n",
       "min        16.900000\n",
       "25%       178.000000\n",
       "50%       258.000000\n",
       "75%       356.000000\n",
       "max      6999.000000\n",
       "Name: price, dtype: float64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### pandas 字符串处理都是借助str方法来实现"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* python原生字符串处理函数:len split replace\n",
    "\n",
    "* 正则表达式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n",
      "['', 'lib', 'b', '']\n",
      "alicaca\n",
      "-1\n"
     ]
    }
   ],
   "source": [
    "b=\"alibaba\"\n",
    "print(len(b))\n",
    "print(b.split(\"a\"))\n",
    "print(b.replace(\"b\",\"c\"))\n",
    "print(b.find(\"n\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课间题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "#已知\n",
    "s1=\"1583人付款\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['1583', '付款']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#以“人”作为分割点对s1进行分割\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1583'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#请用split方法提取出其中的“1583”\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1583'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#请用空字符串\"\"替代s1中的“人付款”，并输出结果\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* str下可以使用的方法表\n",
    "\n",
    "https://www.cnblogs.com/P--K/p/8443995.html\n",
    "\n",
    "重要函数：split;replace;contain"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       32\n",
       "1       30\n",
       "2       32\n",
       "3       30\n",
       "4       31\n",
       "5       30\n",
       "6       30\n",
       "7       33\n",
       "8       32\n",
       "9       30\n",
       "10      29\n",
       "11      39\n",
       "12      30\n",
       "13      30\n",
       "14      30\n",
       "15      30\n",
       "16      30\n",
       "17      32\n",
       "18      32\n",
       "19      30\n",
       "20      28\n",
       "21      30\n",
       "22      32\n",
       "23      32\n",
       "24      29\n",
       "25      30\n",
       "26      30\n",
       "27      30\n",
       "28      29\n",
       "29      32\n",
       "        ..\n",
       "4957    30\n",
       "4958    32\n",
       "4959    32\n",
       "4960    30\n",
       "4961    30\n",
       "4962    30\n",
       "4963    31\n",
       "4964    33\n",
       "4965    32\n",
       "4966    33\n",
       "4967    30\n",
       "4968    30\n",
       "4969    30\n",
       "4970    32\n",
       "4971    32\n",
       "4972    32\n",
       "4973    30\n",
       "4974    30\n",
       "4975    32\n",
       "4976    30\n",
       "4977    33\n",
       "4978    33\n",
       "4979    30\n",
       "4980    30\n",
       "4981    30\n",
       "4982    30\n",
       "4983    32\n",
       "4984    32\n",
       "4985    32\n",
       "4986    30\n",
       "Name: title, Length: 4987, dtype: int64"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.title.str.len()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    32\n",
       "1    30\n",
       "2    32\n",
       "3    30\n",
       "4    31\n",
       "Name: title, dtype: int64"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.title.str.len().head()\n",
    "#计算商品标题的长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    意尔康男\n",
       "1    意尔康旗\n",
       "2    2017\n",
       "3    皮鞋男正\n",
       "4    意尔康男\n",
       "Name: title, dtype: object"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.title.str[0:4].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    意尔康\n",
       "1    意尔康\n",
       "2    201\n",
       "3    皮鞋男\n",
       "4    意尔康\n",
       "Name: title, dtype: object"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.title.str[0:3].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "23752"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.sales.str.replace(\"人付款\",\"\").astype(int).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "23752"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.sales.str.split(\"人\",expand=True)[0].astype(int).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    4987.000000\n",
       "mean        4.762783\n",
       "std        42.756257\n",
       "min         0.000000\n",
       "25%         0.000000\n",
       "50%         0.000000\n",
       "75%         1.000000\n",
       "max      1607.000000\n",
       "Name: 0, dtype: float64"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.sales.str.split(\"人\",expand=True)[0].astype(int).describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1583\n",
       "1    1607\n",
       "2     248\n",
       "3     195\n",
       "4      37\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.sales.str.split(\"人\",expand=True)[0].head()\n",
    "#去掉付款人数后面的汉字保留数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       1583\n",
       "1       1607\n",
       "2        248\n",
       "3        195\n",
       "4         37\n",
       "5         55\n",
       "6        147\n",
       "7         80\n",
       "8         78\n",
       "9         27\n",
       "10        16\n",
       "11         4\n",
       "12       116\n",
       "13        71\n",
       "14         8\n",
       "15        30\n",
       "16        28\n",
       "17         3\n",
       "18        62\n",
       "19        14\n",
       "20        12\n",
       "21         9\n",
       "22        20\n",
       "23         1\n",
       "24        29\n",
       "25        33\n",
       "26        13\n",
       "27         5\n",
       "28         3\n",
       "29        27\n",
       "        ... \n",
       "4957       0\n",
       "4958       0\n",
       "4959       0\n",
       "4960       0\n",
       "4961       0\n",
       "4962       0\n",
       "4963       0\n",
       "4964       0\n",
       "4965       0\n",
       "4966       0\n",
       "4967       0\n",
       "4968       0\n",
       "4969       0\n",
       "4970       0\n",
       "4971       0\n",
       "4972       0\n",
       "4973       0\n",
       "4974       0\n",
       "4975       0\n",
       "4976       0\n",
       "4977       0\n",
       "4978       0\n",
       "4979       0\n",
       "4980       0\n",
       "4981       0\n",
       "4982       0\n",
       "4983       0\n",
       "4984       0\n",
       "4985       0\n",
       "4986       0\n",
       "Name: sales, Length: 4987, dtype: int32"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.sales.str.replace(\"人付款\",\"\").astype(int)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1583\n",
       "1    1607\n",
       "2     248\n",
       "3     195\n",
       "4      37\n",
       "Name: sales, dtype: object"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.sales.str.replace(\"人付款\",\"\").head()\n",
    "#通过替代也可以完成"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "#a.title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0             意尔康男鞋2018春季新款英伦真皮商务休闲皮鞋青年男士皮鞋子男潮\n",
       "4              意尔康男鞋2018春季真皮套脚休闲鞋潮流新款舒适一脚蹬单鞋皮鞋\n",
       "8             意尔康男鞋2018春季新款商务正装真皮系带婚鞋英伦风尖头韩版皮鞋\n",
       "29            意尔康男鞋正品皮鞋2018真皮新款商务休闲鞋套脚男士透气潮男单鞋\n",
       "44            意尔康男鞋正品2018春季休闲皮鞋男士真皮套脚软皮软底爸爸鞋单鞋\n",
       "51            意尔康男鞋2018春季新款百搭平跟真皮驾车皮鞋一脚蹬生活休闲鞋男\n",
       "54              意尔康男鞋2018春季新款真皮男青年商务休闲皮鞋套脚潮流单鞋\n",
       "55            意尔康男鞋2018春季新款圆头真皮软底软面懒人休闲皮鞋豆豆鞋子男\n",
       "56              意尔康男鞋2018春季时尚个性潮鞋真皮透气运动休闲鞋男士板鞋\n",
       "57            意尔康男鞋正品2018春季新款商务休闲皮鞋真皮系带软底男士单鞋潮\n",
       "59              意尔康正品男鞋2018冬新款真皮爸爸鞋老人鞋男士商务休闲皮鞋\n",
       "64            2018春款正品意尔康男鞋真皮休闲鞋男士中年中老年爸爸鞋软底皮鞋\n",
       "69            意尔康男鞋2018新款正品真皮商务正装时尚休闲系带内增高春季皮鞋\n",
       "76            意尔康男鞋 2018春季新款真皮日常休闲皮鞋英伦圆头系带潮单鞋男\n",
       "82            2018春款新品正品意尔康男鞋真皮休闲鞋青年韩版潮皮鞋软底驾车鞋\n",
       "83             意尔康男鞋2018春季新款休闲皮鞋男士真皮青年板鞋潮韩版休闲鞋\n",
       "94            意尔康正品男鞋真皮休闲鞋2018春季中老年皮鞋轻质软底防滑爸爸鞋\n",
       "96             意尔康真皮男鞋2018春季新款商务正装皮鞋男式单鞋旗舰店官方店\n",
       "107            意尔康男鞋2018春季真皮鞋舒适套脚一脚蹬韩版潮休闲皮鞋驾车鞋\n",
       "108           意尔康男鞋2018春季新品休闲皮鞋男士真皮舒适软面皮韩版套脚潮鞋\n",
       "111           2018意尔康男鞋正品新款男士皮鞋系带真皮青年韩版休闲鞋驾车潮鞋\n",
       "115            意尔康男鞋2018新款男士皮鞋真皮休闲鞋时尚休闲皮鞋套脚低帮鞋\n",
       "117            意尔康男鞋2018新款正品真皮英伦系带商务正装男士皮鞋软底婚鞋\n",
       "118           意尔康男鞋2018春季新款真皮舒适商务休闲皮鞋圆头套脚潮流男单鞋\n",
       "119           春季意尔康男鞋休闲鞋真皮系带商务皮鞋潮流青年2018男式单鞋透气\n",
       "124           2018春季意尔康男鞋皮鞋真皮商务休闲鞋男士中年中老年爸爸鞋舒适\n",
       "126     意尔康男鞋2018款系带青年时尚潮流针织运动跑步皮鞋8112GR82171A\n",
       "144            意尔康男鞋2018春季新款专柜正品男士皮鞋韩版休闲青年潮鞋皮鞋\n",
       "147           意尔康男鞋旗舰店官方正品2018春季新款男士真皮休闲鞋懒人鞋皮鞋\n",
       "150           意尔康男鞋正品2018春季新款真皮商务正装休闲鞋子皮鞋套脚爸爸鞋\n",
       "                         ...                  \n",
       "4836          意尔康男鞋2018春款商务正装真皮系带素面轻质透气软面耐磨皮鞋男\n",
       "4842           新品意尔康男鞋冬季加棉鞋男士运动鞋2018真皮板鞋休闲鞋男潮鞋\n",
       "4858          品意尔康2018春季新款板鞋韩版潮流运动休闲男鞋子白色皮鞋小白鞋\n",
       "4864          新品意尔康正品男鞋2018春季新款男士休闲皮鞋真皮手工防滑鞋子男\n",
       "4866          2018春秋韩版百搭新品意尔康皮鞋男舒适透气圆头系带真皮日常休闲\n",
       "4870          新品意尔康官方旗舰店2018春季男士皮鞋款尖头系带商务正装韩版青\n",
       "4874          2018新款真皮正品意尔康官方旗舰店男鞋加绒加厚商务英伦休闲皮鞋\n",
       "4876          新品意尔康2018新款春季一脚蹬豆豆懒人潮鞋男士休闲皮鞋韩版百搭\n",
       "4878          新品意尔康2018春季男鞋韩版百搭板鞋潮流英伦男士休闲皮鞋精神社\n",
       "4887          2018春季意尔康皮鞋男轻质真皮松紧带男士韩版潮流懒人运动休闲鞋\n",
       "4888          2018春季意尔康单鞋男透气软底系带真皮男士韩版英伦套脚皮鞋男潮\n",
       "4892           新品意尔康男鞋冬季加棉鞋男士运动鞋2018真皮板鞋休闲鞋男潮鞋\n",
       "4899         正品意尔康男鞋2018新款男士头层真皮休闲鞋软底透气特大码47皮鞋\n",
       "4900          正品意尔康男鞋2018春季新款真皮休闲男鞋韩版百搭运动头层软皮鞋\n",
       "4909           新品意尔康2018春季款贝壳鞋男士板鞋潮流黑白运动情侣休闲皮鞋\n",
       "4913          新品意尔康2018新款春季男鞋韩版潮流男士休闲皮鞋商务板鞋百搭英\n",
       "4920           新品意尔康2018春季英伦男士真皮鞋子休闲皮鞋韩版潮流男鞋百搭\n",
       "4928          意尔康官方旗舰店2018春季新款真皮男鞋韩版潮鞋日常休闲鞋男皮鞋\n",
       "4935          新品意尔康春季男鞋2018新款豆豆鞋潮鞋男士休闲鞋韩版皮鞋一脚蹬\n",
       "4936          2018春季意尔康单鞋男商务休闲透气真皮男士软底套脚方头懒人皮鞋\n",
       "4937           新品意尔康2018春季英伦男士真皮鞋子休闲皮鞋韩版潮流男鞋百搭\n",
       "4945          2018新品意尔康牛皮凉鞋夏季舒适休闲透气潮流真皮凉鞋男士沙滩鞋\n",
       "4948          官方旗舰店意尔康2018夏季新款男士凉鞋真皮露趾休闲沙滩鞋防水鞋\n",
       "4956          新品意尔康2018新款春季皮鞋男黑色皮鞋青年男鞋英伦商务皮鞋男士\n",
       "4958          2018春季正品意尔康男鞋休闲皮鞋真皮套脚爸爸鞋保暖绒商务男单鞋\n",
       "4965          新品意尔康官方旗舰店2018春季款男士休闲男鞋子小皮鞋英伦潮流豆\n",
       "4970          新品意尔康2018新款春季平底板鞋男士休闲皮鞋韩版潮流百搭男鞋子\n",
       "4983          新品意尔康2018春秋季男士头层牛皮软底软皮休闲皮鞋套脚外贸男鞋\n",
       "4984          新品意尔康男鞋夏季2018新款潮鞋休闲鞋韩版百搭鞋子真皮男士单鞋\n",
       "4985          新品意尔康皮鞋男夏季2018新款潮鞋反绒男士休闲鞋百搭鞋子真皮透\n",
       "Name: title, Length: 918, dtype: object"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[a.title.str.contains(\"2018\")].title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "#a[a.title.str.contains(\"2018\")].title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0             意尔康男鞋2018春季新款英伦真皮商务休闲皮鞋青年男士皮鞋子男潮\n",
       "4              意尔康男鞋2018春季真皮套脚休闲鞋潮流新款舒适一脚蹬单鞋皮鞋\n",
       "8             意尔康男鞋2018春季新款商务正装真皮系带婚鞋英伦风尖头韩版皮鞋\n",
       "29            意尔康男鞋正品皮鞋2018真皮新款商务休闲鞋套脚男士透气潮男单鞋\n",
       "44            意尔康男鞋正品2018春季休闲皮鞋男士真皮套脚软皮软底爸爸鞋单鞋\n",
       "51            意尔康男鞋2018春季新款百搭平跟真皮驾车皮鞋一脚蹬生活休闲鞋男\n",
       "54              意尔康男鞋2018春季新款真皮男青年商务休闲皮鞋套脚潮流单鞋\n",
       "55            意尔康男鞋2018春季新款圆头真皮软底软面懒人休闲皮鞋豆豆鞋子男\n",
       "56              意尔康男鞋2018春季时尚个性潮鞋真皮透气运动休闲鞋男士板鞋\n",
       "57            意尔康男鞋正品2018春季新款商务休闲皮鞋真皮系带软底男士单鞋潮\n",
       "59              意尔康正品男鞋2018冬新款真皮爸爸鞋老人鞋男士商务休闲皮鞋\n",
       "64            2018春款正品意尔康男鞋真皮休闲鞋男士中年中老年爸爸鞋软底皮鞋\n",
       "69            意尔康男鞋2018新款正品真皮商务正装时尚休闲系带内增高春季皮鞋\n",
       "76            意尔康男鞋 2018春季新款真皮日常休闲皮鞋英伦圆头系带潮单鞋男\n",
       "82            2018春款新品正品意尔康男鞋真皮休闲鞋青年韩版潮皮鞋软底驾车鞋\n",
       "83             意尔康男鞋2018春季新款休闲皮鞋男士真皮青年板鞋潮韩版休闲鞋\n",
       "94            意尔康正品男鞋真皮休闲鞋2018春季中老年皮鞋轻质软底防滑爸爸鞋\n",
       "96             意尔康真皮男鞋2018春季新款商务正装皮鞋男式单鞋旗舰店官方店\n",
       "107            意尔康男鞋2018春季真皮鞋舒适套脚一脚蹬韩版潮休闲皮鞋驾车鞋\n",
       "108           意尔康男鞋2018春季新品休闲皮鞋男士真皮舒适软面皮韩版套脚潮鞋\n",
       "111           2018意尔康男鞋正品新款男士皮鞋系带真皮青年韩版休闲鞋驾车潮鞋\n",
       "115            意尔康男鞋2018新款男士皮鞋真皮休闲鞋时尚休闲皮鞋套脚低帮鞋\n",
       "117            意尔康男鞋2018新款正品真皮英伦系带商务正装男士皮鞋软底婚鞋\n",
       "118           意尔康男鞋2018春季新款真皮舒适商务休闲皮鞋圆头套脚潮流男单鞋\n",
       "119           春季意尔康男鞋休闲鞋真皮系带商务皮鞋潮流青年2018男式单鞋透气\n",
       "124           2018春季意尔康男鞋皮鞋真皮商务休闲鞋男士中年中老年爸爸鞋舒适\n",
       "126     意尔康男鞋2018款系带青年时尚潮流针织运动跑步皮鞋8112GR82171A\n",
       "144            意尔康男鞋2018春季新款专柜正品男士皮鞋韩版休闲青年潮鞋皮鞋\n",
       "147           意尔康男鞋旗舰店官方正品2018春季新款男士真皮休闲鞋懒人鞋皮鞋\n",
       "150           意尔康男鞋正品2018春季新款真皮商务正装休闲鞋子皮鞋套脚爸爸鞋\n",
       "                         ...                  \n",
       "4836          意尔康男鞋2018春款商务正装真皮系带素面轻质透气软面耐磨皮鞋男\n",
       "4842           新品意尔康男鞋冬季加棉鞋男士运动鞋2018真皮板鞋休闲鞋男潮鞋\n",
       "4858          品意尔康2018春季新款板鞋韩版潮流运动休闲男鞋子白色皮鞋小白鞋\n",
       "4864          新品意尔康正品男鞋2018春季新款男士休闲皮鞋真皮手工防滑鞋子男\n",
       "4866          2018春秋韩版百搭新品意尔康皮鞋男舒适透气圆头系带真皮日常休闲\n",
       "4870          新品意尔康官方旗舰店2018春季男士皮鞋款尖头系带商务正装韩版青\n",
       "4874          2018新款真皮正品意尔康官方旗舰店男鞋加绒加厚商务英伦休闲皮鞋\n",
       "4876          新品意尔康2018新款春季一脚蹬豆豆懒人潮鞋男士休闲皮鞋韩版百搭\n",
       "4878          新品意尔康2018春季男鞋韩版百搭板鞋潮流英伦男士休闲皮鞋精神社\n",
       "4887          2018春季意尔康皮鞋男轻质真皮松紧带男士韩版潮流懒人运动休闲鞋\n",
       "4888          2018春季意尔康单鞋男透气软底系带真皮男士韩版英伦套脚皮鞋男潮\n",
       "4892           新品意尔康男鞋冬季加棉鞋男士运动鞋2018真皮板鞋休闲鞋男潮鞋\n",
       "4899         正品意尔康男鞋2018新款男士头层真皮休闲鞋软底透气特大码47皮鞋\n",
       "4900          正品意尔康男鞋2018春季新款真皮休闲男鞋韩版百搭运动头层软皮鞋\n",
       "4909           新品意尔康2018春季款贝壳鞋男士板鞋潮流黑白运动情侣休闲皮鞋\n",
       "4913          新品意尔康2018新款春季男鞋韩版潮流男士休闲皮鞋商务板鞋百搭英\n",
       "4920           新品意尔康2018春季英伦男士真皮鞋子休闲皮鞋韩版潮流男鞋百搭\n",
       "4928          意尔康官方旗舰店2018春季新款真皮男鞋韩版潮鞋日常休闲鞋男皮鞋\n",
       "4935          新品意尔康春季男鞋2018新款豆豆鞋潮鞋男士休闲鞋韩版皮鞋一脚蹬\n",
       "4936          2018春季意尔康单鞋男商务休闲透气真皮男士软底套脚方头懒人皮鞋\n",
       "4937           新品意尔康2018春季英伦男士真皮鞋子休闲皮鞋韩版潮流男鞋百搭\n",
       "4945          2018新品意尔康牛皮凉鞋夏季舒适休闲透气潮流真皮凉鞋男士沙滩鞋\n",
       "4948          官方旗舰店意尔康2018夏季新款男士凉鞋真皮露趾休闲沙滩鞋防水鞋\n",
       "4956          新品意尔康2018新款春季皮鞋男黑色皮鞋青年男鞋英伦商务皮鞋男士\n",
       "4958          2018春季正品意尔康男鞋休闲皮鞋真皮套脚爸爸鞋保暖绒商务男单鞋\n",
       "4965          新品意尔康官方旗舰店2018春季款男士休闲男鞋子小皮鞋英伦潮流豆\n",
       "4970          新品意尔康2018新款春季平底板鞋男士休闲皮鞋韩版潮流百搭男鞋子\n",
       "4983          新品意尔康2018春秋季男士头层牛皮软底软皮休闲皮鞋套脚外贸男鞋\n",
       "4984          新品意尔康男鞋夏季2018新款潮鞋休闲鞋韩版百搭鞋子真皮男士单鞋\n",
       "4985          新品意尔康皮鞋男夏季2018新款潮鞋反绒男士休闲鞋百搭鞋子真皮透\n",
       "Name: title, Length: 918, dtype: object"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[a.title.str.contains(\"2018\")].title\n",
    "#注意contains的结果是一个二分序列\n",
    "#过滤所有title里面有2018的商品"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      0\n",
       "0  2018\n",
       "1   NaN\n",
       "2  2017\n",
       "3   NaN\n",
       "4  2018"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.title.str.extract('(\\d+)').head()\n",
    "#正则表达式，抽取所有匹配到的数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [],
   "source": [
    "#a.location.str.split(\" \",expand=True)[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 基于处理后的序列进行分组\n",
    "\n",
    "* 注意这里要求索引能够对应"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       浙江\n",
       "1       浙江\n",
       "2       浙江\n",
       "3       浙江\n",
       "4       浙江\n",
       "5       浙江\n",
       "6       浙江\n",
       "7       浙江\n",
       "8       浙江\n",
       "9       江苏\n",
       "10      浙江\n",
       "11      浙江\n",
       "12      浙江\n",
       "13      浙江\n",
       "14      浙江\n",
       "15      浙江\n",
       "16      浙江\n",
       "17      浙江\n",
       "18      浙江\n",
       "19      福建\n",
       "20      浙江\n",
       "21      浙江\n",
       "22      浙江\n",
       "23      福建\n",
       "24      浙江\n",
       "25      浙江\n",
       "26      浙江\n",
       "27      浙江\n",
       "28      浙江\n",
       "29      浙江\n",
       "        ..\n",
       "4957    福建\n",
       "4958    浙江\n",
       "4959    福建\n",
       "4960    浙江\n",
       "4961    浙江\n",
       "4962    上海\n",
       "4963    上海\n",
       "4964    浙江\n",
       "4965    浙江\n",
       "4966    福建\n",
       "4967    福建\n",
       "4968    福建\n",
       "4969    福建\n",
       "4970    福建\n",
       "4971    福建\n",
       "4972    福建\n",
       "4973    福建\n",
       "4974    福建\n",
       "4975    福建\n",
       "4976    福建\n",
       "4977    福建\n",
       "4978    福建\n",
       "4979    福建\n",
       "4980    福建\n",
       "4981    福建\n",
       "4982    福建\n",
       "4983    广东\n",
       "4984    福建\n",
       "4985    福建\n",
       "4986    上海\n",
       "Name: 0, Length: 4987, dtype: object"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.location.str.split(\" \",expand=True)[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    浙江\n",
       "1    浙江\n",
       "2    浙江\n",
       "3    浙江\n",
       "4    浙江\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.location.str.split(\" \",expand=True)[0].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0\n",
       "上海     154\n",
       "北京     339\n",
       "吉林       1\n",
       "四川       4\n",
       "安徽      24\n",
       "山东      44\n",
       "山西      39\n",
       "广东     284\n",
       "江苏     120\n",
       "江西      42\n",
       "河北      86\n",
       "河南     393\n",
       "浙江    2470\n",
       "湖北      27\n",
       "福建     952\n",
       "贵州       2\n",
       "辽宁       3\n",
       "重庆       3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.groupby(a.location.str.split(\" \",expand=True)[0]).size()\n",
    "#求各个省份的商品数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "title\n",
       "False    4069\n",
       "True      918\n",
       "dtype: int64"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.groupby(a.title.str.contains(\"2018\")).size()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "#a.title.str.contains(\"2018\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课间题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 求出各个市的商品数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1\n",
       "上饶        1\n",
       "东莞        8\n",
       "中山        1\n",
       "临沂       15\n",
       "丽水      938\n",
       "九江       15\n",
       "保定        2\n",
       "南京        9\n",
       "南平       10\n",
       "南昌       23\n",
       "厦门       18\n",
       "台州        2\n",
       "合肥       21\n",
       "嘉兴        4\n",
       "太原       39\n",
       "宁德      126\n",
       "宁波        8\n",
       "安庆        3\n",
       "宜春        3\n",
       "宿迁        4\n",
       "常州        5\n",
       "广元        1\n",
       "广州      264\n",
       "徐州        2\n",
       "恩施        1\n",
       "成都        3\n",
       "扬州       92\n",
       "杭州      107\n",
       "松原        1\n",
       "武汉       10\n",
       "汕头        5\n",
       "沈阳        3\n",
       "泉州      798\n",
       "济南        1\n",
       "深圳        4\n",
       "温岭       10\n",
       "温州     1275\n",
       "湖州      118\n",
       "潍坊       21\n",
       "珠海        2\n",
       "石家庄      70\n",
       "绍兴        1\n",
       "苏州        5\n",
       "莱芜        1\n",
       "衢州        3\n",
       "襄阳        1\n",
       "贵阳        2\n",
       "连云港       1\n",
       "邢台       14\n",
       "郑州      393\n",
       "金华        4\n",
       "镇江        2\n",
       "青岛        6\n",
       "黄石       15\n",
       "dtype: int64"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 求出商品“info.鞋面材质”中各个特征的商品数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "info.鞋面材质\n",
       "PU             671\n",
       "二层牛皮（除牛反绒）     605\n",
       "二层猪皮             8\n",
       "人造革             80\n",
       "塑胶              10\n",
       "多种材质拼接          21\n",
       "太空革              9\n",
       "头层牛皮（除牛反绒）    3470\n",
       "头层猪皮             6\n",
       "布                8\n",
       "棉布               1\n",
       "牛仔布              2\n",
       "牛反绒             12\n",
       "磨砂皮             14\n",
       "绒面              15\n",
       "网布               7\n",
       "羊皮毛一体            1\n",
       "超纤              35\n",
       "超纤皮              1\n",
       "鳄鱼皮              4\n",
       "dtype: int64"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 求所有商品的的总付款人数(注意同样要进行类型转换)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "23752"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 选择title中包含春季的商品前五行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 求出所有在\"info.颜色分类\"中有白色的商品，并求出其数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "306"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
